package com.yootk.action;

import com.yootk.common.action.abs.AbstractBaseAction;
import com.yootk.service.IMessageService;
import com.yootk.vo.Message2;
import com.yootk.vo.Message3;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/message/*")
public class MessageAction extends AbstractBaseAction {
    private static final Logger LOGGER = LoggerFactory.getLogger(MessageAction.class);

    @Autowired
    private IMessageService messageService;

    @RequestMapping("echo")
    public String echo(String msg) {
        LOGGER.info("接收msg的请求参数，内容为：{}", msg);
        return messageService.echo(msg);
    }

    @RequestMapping(value = "echo2", produces = {"application/json;charset=UTF-8"})
    public Object echo(Message2 message) {
        message.setTitle("【ECHO】" + message.getTitle());
        message.setContent("【ECHO】" + message.getContent());
        return message;
    }

    @RequestMapping(value = "echo3", produces = {"text/xml;charset=UTF-8"})
    public Object echo(Message3 message) {
        message.setTitle("【ECHO】" + message.getTitle());
        message.setContent("【ECHO】" + message.getContent());
        return message;
    }
}
